class DbUtil {

  dbClient = null;

  initTableList = [
    ` CREATE TABLE IF NOT EXISTS session_list (
        id integer NOT NULL PRIMARY KEY AUTOINCREMENT,
        session_id TEXT,
        contact_name TEXT,
        contact_id TEXT,
        last_message TEXT,
        last_time TEXT,
        last_avatar TEXT,
        is_show integer DEFAULT 1,
        is_owner integer,
        create_time TEXT,
        update_time TEXT,
        create_user TEXT,
        update_user TEXT,
        is_del INTEGER DEFAULT 0
      )` ,
    `CREATE TABLE IF NOT EXISTS session_info (
        id integer NOT NULL PRIMARY KEY AUTOINCREMENT,
        message_id TEXT,
        session_id TEXT,
        content TEXT,
        type INTEGER,
        status INTEGER DEFAULT 0,
        is_read INTEGER DEFAULT 0,
        file_path TEXT,
        file_name TEXT,
        file_size REAL,
        create_time TEXT,
        update_time TEXT,
        create_user TEXT,
        update_user TEXT,
        is_del INTEGER DEFAULT 0
      )`,
    `CREATE TABLE IF NOT EXISTS "user_contact" (
                                   "id" INTEGER,
                                   "user_id" TEXT,
                                   "contact_id" TEXT,
                                   "contact_remark" TEXT,
                                   "avatar" TEXT,
                                   "source" TEXT,
                                   "nickname" TEXT,
                                   "we_chat_code" TEXT,
                                   "email" TEXT,
                                   "phone" TEXT,
                                   "area_code" TEXT,
                                   "area" TEXT,
                                   "friend_permission" INTEGER DEFAULT 1,
                                   "type" INTEGER,
                                   "status" INTEGER,
                                   "is_del" INTEGER DEFAULT 0,
                                   "create_time" TEXT,
                                   "update_time" TEXT,
                                   "create_user" TEXT,
                                   "update_user" TEXT,
                                   PRIMARY KEY ("id")
     );`
  ]




  /**
   * 初始化数据库
   * @param db
   * @returns {Promise<unknown>}
   */
  initDB(db) {
    return new Promise((resolve, reject) => {
      this.dbClient = db
      this.initTableList.forEach((table) => {
        db.run(table)
      })

      resolve(true)
    })
  }



}


export default DbUtil
